Public Class Frm_SelectMau

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.btnCancel.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub BtnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFind.Click
        Try

            Dim SQL As String = String.Empty
            Dim DT As DataTable
            SQL = " SELECT ISSELECTED = CONVERT(BIT,0), BILLNO,PACKING, BILLBARCODE AS BARCODE,QTY,REPLACE(GOODSBARCODE,'*','') AS  "
            SQL += " GOODSBARCODE,B.CODE,SUPPERITEM,CNNAME, "
            SQL += " E.COLORCNAME AS COLOR,J.SIZESNAME AS SPEC, B.ENNAME, F.FFULLNAME AS  GOODSTYPE, BILLBARCODE, D.LISTA AS UNIT, PACKINGSPEC "
            SQL += " FROM MAU_PACKINGDESIGNDETAIL A LEFT JOIN BSC_GOODS B ON A.BILLBARCODE = B.CODE    LEFT JOIN "
            SQL += " (SELECT C.ITEMCODE,D.LISTCODE,D.LISTA  FROM  BSC_OTHERDEFINEA C,BSC_OTHERDEFINEB D WHERE "
            SQL += "  C.ITEMCODE = 'UNITDEFIN' AND C.ID = D.ITEMNO) D  ON B.UNIT =D.LISTCODE "
            SQL += "  LEFT JOIN BSC_COLORDEFINE E ON B.COLOR = E.COLORCODE  LEFT JOIN BSC_SIZEDEFINE J ON B.SPEC = J.SIZECODE LEFT JOIN BSC_GOODSTYPE F ON B.GOODSTYPE = F.ID  where 1=1 "


            If Me.TxtBillNo.Text.ToString.Length > 0 Then
                SQL += " and a.BillNo = '" & Me.TxtBillNo.Text.ToString.Trim & "'"
            End If
            If Me.TxtPacking.Text.ToString.Length > 0 Then
                SQL += " and a.Packing = '" & Me.TxtPacking.Text.ToString.Trim & "'"
            End If

            If Me.TxtEnname.Text.ToString.Length > 0 Then
                SQL += " and a.Enname = '" & Me.TxtEnname.Text.ToString.Trim & "'"
            End If

            If Me.TxtBarCode.Text.ToString.Length > 0 Then
                SQL += " and a.GoodsBarCode = '*" & Me.TxtBarCode.Text.ToString.Trim & "*'"
            End If

            DT = Exec(SQL, E_ExecType.DataTable)
            Me.DataGridView1.DataSource = DT

        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try


    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Me.btnOK.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        Try
            Dim DT As DataTable = CType(Me.DataGridView1.DataSource, DataTable)
            If DT.Rows.Count > 0 Then
                If Me.CheckBox1.Checked = True Then
                    For Each row As DataRow In DT.Rows
                        row("ISSELECTED") = True
                    Next
                End If
                If Me.CheckBox1.Checked = False Then
                    For Each row As DataRow In DT.Rows
                        row("ISSELECTED") = False
                    Next
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub Frm_SelectMau_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        Me.btnCancel.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub TxtBillNo_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtBillNo.KeyDown, TxtBarCode.KeyDown, TxtEnname.KeyDown, TxtPacking.KeyDown
        If e.KeyCode = Keys.Enter Then
            BtnFind_Click(Nothing, Nothing)
        End If
    End Sub
End Class